<template>
	<view class="add">
		<u--form
		ref="form1"
		>
		<u-form-item
		label="学历"
		prop="offer.education"
	    labelWidth='80'
		ref="item1"
		>
		<u--input
		v-model="offer.education"
		placeholder="请填写学历"
		border="none"
		inputAlign='right'
		@blur="educationblur"
		></u--input>
		</u-form-item>
		
		<u-form-item
		label="住址"
		labelWidth='80'
		prop="offer.address"
		ref="item1"
		>
		<u--input
		v-model="offer.address"
		placeholder="请填写住址"
		border="none"
		inputAlign='right'
		@blur="addressblur"
		></u--input>
		</u-form-item>
		
		<u-form-item
		label="期望薪资"
		labelWidth='80'
		prop="offer.money"
		ref="item1"
		>
		<u--input
		v-model="offer.money"
		placeholder="请填写期望薪资"
		border="none"
		inputAlign='right'
		@blur="moneyblur"
		></u--input>
		</u-form-item>
		
		<u-form-item
		label="工作经历"
		labelWidth='80'
		prop="offer.experience"
		ref="item1"
		>
		<u--input
		v-model="offer.experience"
		inputAlign='right'
		placeholder="请填写工作经历"
		border="none"
		@blur="experienceblur"
		></u--input>
		</u-form-item>
		
		<u-form-item
		label="个人简介"
		labelWidth='80'
		prop="offer.individualResume"
		ref="item1"
		>
		<u--textarea 
		v-model="offer.individualResume" 
		placeholder="请输入内容" 
		autoHeight  
		@blur="indiblur"
		/>
		
		</u-form-item>
		
		</u--form>

	</view>
</template>
<script setup>
import { getCurrentInstance, onMounted, ref } from 'vue';
import {flexresume} from '../../../api/jobApi.js'
import {onLoad} from '@dcloudio/uni-app'

const offer =ref({}) //简历
const id= ref()  //id

//失去焦点触发更改学历
const educationblur=(evt)=>{

	if(!evt){
		uni.showToast({
			title: '内容不能为空',
			duration: 1000,
			icon:'error'
		});
	return;
	}
		
	let data={
	   education:evt
	}
	changecon(data)	
}

//失去焦点触发更改住址
const addressblur=(evt)=>{
	console.log(evt);
	if(!evt){
		uni.showToast({
			title: '内容不能为空',
			duration: 1000,
			icon:'error'
		});
	return;
	}
	
	let data={
	   address:evt
	}
	changecon(data)
}

//失去焦点触发更改薪资
const moneyblur=(evt)=>{
	console.log(evt);
	if(!evt){
		uni.showToast({
			title: '内容不能为空',
			duration: 1000,
			icon:'error'
		});
	return;
	}
	
	let data={
	   money:evt
	}
	changecon(data)
}

//失去焦点触发更改工作年限
const experienceblur=(evt)=>{
	console.log(evt);
	if(!evt){
		uni.showToast({
			title: '内容不能为空',
			duration: 1000,
			icon:'error'
		});
	return;
	}
	
	let data={
	   experience:evt
	}
	changecon(data)
}

//失去焦点触发更改个人简历
const indiblur=(evt)=>{
	console.log(evt);
	if(!evt){
		uni.showToast({
			title: '内容不能为空',
			duration: 1000,
			icon:'error'
		});
	return;
	}
	
	let data={
	   individualResume:evt.detail.value
	}
	changecon(data)
}

//更改内容的接口
const changecon =async(evt)=>{
	console.log(evt);
	
	let res = await flexresume({
		header:{
			'Authorization':uni.getStorageSync('token')
		},
		data:{
		id:id.value,
		...evt
		}
	})
	
	if(res.code !=200){
		uni.showToast({
			title:'修改成功'
		})
			
		offer.value={
			...offer.value,
				...evt
		}
		
	}
	console.log(offer.value);
}

onLoad((option)=>{
	offer.value=JSON.parse(option.offer)
	id.value = option.id
	
})


// onMounted(()=>{
// 	offer.value=JSON.parse(getCurrentInstance().attrs.offer) 
//     id.value = getCurrentInstance().attrs.id
// 	console.log( offer.value );
// })

</script>
<style lang="scss">
::v-deep uni-page-wrapper{
background-color: rgb(247, 248, 250);	
}
.add{
	height: 100%;
	background-color: rgb(247, 248, 250);
	padding: 0px 10px;
	overflow: hidden;

	.u-form-item{
	background-color:#fff;
	padding: 0px 10px;	
	margin: 5px;
	border-radius: 8px;
	}
	
}

</style>
